import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class Test {

    public static void OrderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    public static void NotOrderArray(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }

    public static void testOrder() {
        int[] array = new int[10_0000];
        //OrderArray(array);//有序
        NotOrderArray(array);//无序

        testInset(array);//直接插入排序
        testShell(array);//希尔排序
        testSelect(array);//选择排序
        testHeap(array);//堆排序
        testBubble(array);//冒泡排序
        testQuick(array);//快速排序
        testMerge(array);//归并排序

    }

    public static void testInset(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insetSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序的耗时：" + (endTime - startTime));
    }

    public static void testShell(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序的耗时：" + (endTime - startTime));
    }

    public static void testSelect(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序的耗时：" + (endTime - startTime));
    }

    public static void testHeap(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.HeapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序的耗时：" + (endTime - startTime));
    }

    public static void testBubble(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序的耗时：" + (endTime - startTime));
    }

    public static void testQuick(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序的耗时：" + (endTime - startTime));
    }

    public static void testMerge(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序的耗时：" + (endTime - startTime));
    }

    public static void main(String[] args) {
        testOrder();
    }

    public static void main8(String[] args) {
        int[] array = {9,5,4,6,3,2,1,0,4,7,8,4,5,3,2,1,6,9,8,1};
        System.out.println("计数排序前：" + Arrays.toString(array));
        Sort.countSort(array);
        System.out.println("计数排序后：" + Arrays.toString(array));
    }

    public static void main7(String[] args) {
        int[] array = {12,3,6,2,5,50,79,40,60,33,89,99,132};
        System.out.println("归并排序前：" + Arrays.toString(array));
        Sort.mergeSort(array);
        System.out.println("归并排序后：" + Arrays.toString(array));
    }

    public static void main6(String[] args) {
        int[] array = {12,3,6,2,5,50,79,40,60,33,89,99,132};
        System.out.println("快速排序前：" + Arrays.toString(array));
        Sort.quickSort(array);
        System.out.println("快速排序后：" + Arrays.toString(array));
    }

    public static void main5(String[] args) {
        int[] array = {12,3,6,2,5};
        System.out.println("冒泡排序前：" + Arrays.toString(array));
        Sort.bubbleSort(array);
        System.out.println("冒泡排序后：" + Arrays.toString(array));
    }
    public static void main4(String[] args) {
        int[] array = {12,3,6,2,5};
        System.out.println("堆排序前：" + Arrays.toString(array));
        Sort.HeapSort(array);
        System.out.println("堆排序后：" + Arrays.toString(array));
    }
    public static void main3(String[] args) {
        int[] array = {12,3,6,2,5};
        System.out.println("选择排序前：" + Arrays.toString(array));
        Sort.selectSort2(array);
        System.out.println("选择排序后：" + Arrays.toString(array));
    }
    public static void main2(String[] args) {
        int[] array = {9,1,2,5,7,4,8,6,3,5};
        System.out.println("希尔排序前：" + Arrays.toString(array));
        Sort.shellSort(array);
        System.out.println("希尔排序后：" + Arrays.toString(array));
    }

    public static void main1(String[] args) {
        int[] array = {15,2,5,7,3};
        System.out.println("排序前：" + Arrays.toString(array));
        Sort.insetSort(array);
        System.out.println("排序后：" + Arrays.toString(array));
    }
}
